home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Math Functions / AreaXYBetweenCursors < prev    next >
Text File  |  1996-03-29  |  3KB  |  104 lines

  1. #include <AreaXY>
  2.  
  3. | LH950924: Modernized to Igor Pro 3.0 level
  4. | JP960329: Works with XY traces (Display ywave vs xwave) and non-XY traces (Display ywave)
  5.  
  6. Macro PutCursorsOnWave(w)
  7.     String w
  8.     Prompt w,"wave to put cursors on",popup,TraceNameList("",";",1)
  9.     ShowInfo;Cursor/P A,$w,0;Cursor/P B,$w,numpnts(TraceNameToWaveRef("",w))-1
  10. End
  11.  
  12. Function fAreaXYBetweenCursors()
  13.     String wvaName,wvbName,wvxName
  14.     WAVE wva=CsrWaveRef(A)
  15.     WAVE wvb=CsrWaveRef(B)
  16.     wvaName= GetWavesDataFolder(wva,4)
  17.     wvbName= GetWavesDataFolder(wvb,4)
  18.     if( CmpStr(wvaName,wvbName)) != 0 )
  19.         Abort "Cursors must be on the same wave (Cursor A is on wave \""+wvaName+"\"; Cursor B isn't)."
  20.         return NaN
  21.     endif
  22.     Variable p1=pcsr(A)
  23.     Variable p2=pcsr(B)
  24.     if( p1 > p2 )
  25.         p1=p2
  26.         p2=pcsr(A)
  27.     endif
  28.     | extract the subrange between the cursors
  29.     Duplicate/O/R=[p1,p2] wva, s_ywave
  30.     WAVE wvx= CsrXWaveRef(A)            // could be non-existant
  31.     if( WaveExists(wvx) )
  32.         Duplicate/O/R=[p1,p2] wvx,s_xwave
  33.         if( IsMonotonicIncrP1P2(s_xwave,0,p2-p1) == 0 )
  34.             Abort "X values between cursors aren't monotonically increasing or decreasing."
  35.             return NaN
  36.         endif
  37.     endif
  38.     Variable x1=hcsr(A)
  39.     Variable x2=hcsr(B)
  40.     if( x1 > x2 )
  41.         x1= x2
  42.         x2=hcsr(A)
  43.     endif
  44.     Variable a
  45.     if( WaveExists(wvx) )
  46.         a= AreaXY(s_xwave,s_ywave,x1,x2)
  47.         Killwaves/Z s_xwave
  48.     else
  49.         a= area(s_ywave,x1,x2)
  50.     endif
  51.     Killwaves/Z s_ywave
  52.     return A
  53. end
  54.  
  55.  
  56. Macro AreaXYBetweenCursors()
  57.     PauseUpdate;Silent 1
  58.  
  59.     Variable/G V_areaXY= fAreaXYBetweenCursors()
  60.     Print "area between x= ",hcsr(A)," and ",hcsr(B)," = ",V_areaXY
  61. End
  62.  
  63. | This removes the area of the baseline that stretches between the two cursors
  64. Macro AreaXYBetweenCursorsLessBase()
  65.     PauseUpdate;Silent 1
  66.     Variable/G V_areaXY= fAreaXYBetweenCursors()
  67.     Variable x1=hcsr(A)
  68.     Variable x2=hcsr(B)
  69.     if( x1 > x2 )
  70.         x1= x2
  71.         x2=hcsr(A)
  72.     endif
  73.     V_AreaXY -=  (vcsr(A)+vcsr(B))/2*(x2-x1)     | remove trapezoidal baseline (straight line between cursors)
  74.     Print "adjusted area between x= ",x1," and ",x2," = ",V_areaXY
  75. End
  76.  
  77.  
  78. Macro HideCursors()
  79.     HideInfo;Cursor/K A;Cursor/K B
  80. End
  81.  
  82. | IsMonotonicIncrP1P2() returns true if the wave has delta(wave(x))/delta(x) > 0 for all points from p1 to p2.
  83. | p1 must be < p2; these are point numbers, not x values
  84. Function IsMonotonicIncrP1P2(wv,p1,p2)
  85.     Wave wv
  86.     Variable p1,p2
  87.     
  88.     Variable diff,i=p1
  89.     Variable last=p2
  90.     Variable incr=(wv[p1+1]-wv[p1])>0
  91.     do
  92.         if(incr)
  93.             diff=wv[i+1]-wv[i]
  94.         else
  95.             diff=wv[i]-wv[i+1]
  96.         endif
  97.         if (diff<=0)
  98.             return 0    | not monotonically increasing. (we DO NOT allow wv[i+1] == wv[i]).
  99.         endif
  100.         i += 1
  101.     while (i < last)
  102.     return 1            | success
  103. End
  104.